import { useMainStore } from '@/store'
import { useConfigStore } from '@/store/config'
import { useCommonState } from '@/store/common'
import { Router } from 'vue-router'

// 系统状态初始化， 进入时加载一次，之后不再加载
export const appInitState = async (router: Router): Promise<Setting.Config> => {
  try {
    await Promise.all([
      useMainStore().initMenu(),
      useConfigStore().initData(),
      useCommonState().initData()
    ])
  } catch (e) {
    await router.push('/login')
    return {} as any
  }
  return {
    title: '后台管理'
  }
}
